package android.fwirk.obj;

import java.util.ArrayList;

import android.content.Context;
import android.fwirk.R;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class StatusMessageAdapter extends ArrayAdapter<StatusMessage> {

        public StatusMessageAdapter(Context context, int textViewResourceId) {
            super(context, textViewResourceId);
        }
        
        public StatusMessageAdapter(Context context, int textViewResourceId, ArrayList<StatusMessage> items) {
            super(context, textViewResourceId, items);
        }
        
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                if (v == null) {
                    LayoutInflater vi = (LayoutInflater)(getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE));
                    v = vi.inflate(R.layout.row, null);
                }
                StatusMessage sm = getItem(position);
                if (sm != null) {
                        TextView tt = (TextView) v.findViewById(R.id.toptext);
                        TextView bt = (TextView) v.findViewById(R.id.bottomtext);
                        ImageView ic = (ImageView) v.findViewById(R.id.icon);
                        if (tt != null) {
                            String status=sm.getStatus();
                            status=status.replace("<br/>", "\n");
                            if(status.length()>30) {
                            	status=status.substring(0, 30).concat("...");
                            }
                        	tt.setText(status);  
                        }
                        if(bt != null){
                        	bt.setText(sm.getMisc());
                        }
                        if(ic!=null) {
                        	if(sm.getBitmap()!=null) {
                        		ic.setImageBitmap(sm.getBitmap());
                        	}
                        	else {
                        		ic.setImageResource(sm.getDrawID());
                        	}
                        	
                        }
                }
                return v;
        }
}
